package com.springboot.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.springboot.cloud.entities.Article;
import com.springboot.cloud.service.ArticleService;

@RestController
public class ArticleController {

	@Autowired
	private ArticleService aservice;

		@RequestMapping(value = "/geta/{start}",method = RequestMethod.GET)
		public List<Article> geta(@PathVariable("start") int start) {
			return aservice.geta(start,10);
		}
		@RequestMapping(value = "/adda", method = RequestMethod.POST)
		public boolean adda(@RequestBody Article a){
			return aservice.adda(a);
		};
		@RequestMapping(value = "/getone/{id}", method = RequestMethod.GET)
		public Article getone(@PathVariable int id) {
			return aservice.getone(id);
		};
		@RequestMapping(value = "/getmyarticle/{uid}", method = RequestMethod.GET)
		public List<Article> getmyarticle(@PathVariable("uid") int uid) {
			return aservice.getmyarticle(uid);
		};
		@RequestMapping(value = "/getfavorite/{id}", method = RequestMethod.GET)
		public List<Article> getfavorite(@PathVariable("id") int id) {
			return aservice.getfavorite(id);
		};
		@RequestMapping(value = "/addlike/{id}", method = RequestMethod.GET)
		public boolean addlike(@PathVariable("id") int id) {
			System.out.println(id);
			return aservice.addlike(id);
		};
		@RequestMapping(value = "/addnolike/{id}", method = RequestMethod.GET)
		public boolean addnolike(@PathVariable("id") int id) {
			return aservice.addnolike(id);
		};
		@RequestMapping(value = "/addfavorite/{id}/{aid}", method = RequestMethod.GET)
		public boolean addfavorite(@PathVariable(value="id")int id,@PathVariable(value="aid")int aid) {
			return aservice.addfavorite(id,aid);
		};
}
